//
//  HNBankListSegment.m
//  XDEducation
//
//  Created by 星道 on 17/5/22.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNBankListSegment.h"

@implementation HNBankListSegment
{
    IBOutlet NSLayoutConstraint *_BlueLine;
    void(^_SelectIndex)(NSInteger,NSString *);
    __weak UIButton *_TempButton;
}

- (instancetype)init_HNWithSelectIndex:(void (^)(NSInteger, NSString *))SelectIndex
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNBankListSegment description] owner:nil options:nil] lastObject];
    if (self)
    {
        _SelectIndex = SelectIndex;
        
        [self ClickButton:(UIButton *)[self viewWithTag:1100]];
    }
    return self;
}



- (IBAction)ClickButton:(UIButton *)sender
{
    if (sender == _TempButton) return;
    if ([sender.titleLabel.text isEqualToString:@"红花"])
    {
        [self MoveLine:0 Sender:sender];
    }
    else if ([sender.titleLabel.text isEqualToString:@"五星"])
    {
        [self MoveLine:1 Sender:sender];
    }
    else
    {
        [self MoveLine:2 Sender:sender];
    }
    _TempButton = sender;
}

- (void)MoveLine:(NSInteger)Index Sender:(UIButton *)sender
{
    [UIView animateWithDuration:0.3 animations:^{
       
        _BlueLine.constant = (ScreenW/3.0) * Index;
        [self layoutIfNeeded];
    }];
    _SelectIndex (Index,sender.titleLabel.text);
}
@end
